function foo(num) {
    // console.log(num);
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve(num * 2)
        }, 1000)
    })
}

function* gen() {
    const num1 = yield foo(1)
    const num2 = yield foo(num1)
    const num3 = yield foo(num2)
    return num3
}

const g = gen()
const next1 = g.next() // { value: Promise { <pending> }, done: false }
next1.value.then(res1 => {
    console.log(res1);

    const next2 = g.next(res1)
    next2.value.then(res2 => {
        console.log(res2);

        const next3 = g.next(res2)
        next3.value.then(res3 => {
            console.log(res3);

            g.next(res3)
        })
    })
})

console.log(g.next()); // { value: 1, done: false }
console.log(g.next()); // { value: 2, done: false }
console.log(g.next()); // { value: 3, done: false }
console.log(g.next()); // { value: 4, done: true }

// function* gen() {
//     const num1 = yield 1
//     console.log(num1); // 111
//     const num2 = yield 2
//     const num3 = yield 3
//     return 4
// }

// const g = gen()
// console.log(g.next()); // { value: 1, done: false }
// console.log(g.next(111));